<template>
	<view class="categories-wrap">
		<view class="nav-item" :class="{'active':value == item.id}" v-for="item in obtCategories" :key="item.id" @click="selectCategories(item)">
			{{item.name}}
		</view>
	</view>
</template>

<script>
	import * as types from "@/store/types.js";

	export default {
		props:{
			value:{
				type:Number,
				default:0
			}
		},
		computed: {
			//取出商品分类
			obtCategories() {
				let {categoryList=[]} =  this.$store.getters.gcategories||[];	
				return [{id:0,name:'全部',create:"0"},...categoryList];
			},
		},
		methods: {
			Load(){
				this.$store.dispatch(types.ACategories).then(res=>{
					this.$parent.Load('refresh');
				});
			},
			selectCategories(item){
				this.$emit('input',item.id)
				this.$parent.Load('refresh');
			}
		},
		created() {
			this.Load();
		}
	}
</script>

<style scope lang="less">
	@import "./Comp_CategoriesNav.less";
</style>
